package hellfire.platform.screens;

import hellfire.platform.input.TouchListener;
import hellfire.system.graphics.GLDrawable;
import hellfire.system.graphics.GLVec2;

import java.util.Vector;

import android.util.Log;
import android.view.MotionEvent;

public abstract class AbstractGameScreen 
{
	protected Vector<Object> screenItems = new Vector<Object>();
	protected TouchListener focusedObject = null;
	
	public void focusTouchListener(TouchListener listener)
	{
		focusedObject = listener;
	}
	
	public void addItem(Object screenItem)
	{
		screenItems.add(screenItem);
	}
	
	public abstract void gameFrame();
	
	public void draw(float[] matrix)
	{
		for(int i = 0; i < screenItems.size(); i++)
		{
			Object item = screenItems.get(i);
			if(item instanceof GLDrawable)
				((GLDrawable) item).draw(matrix);
		}
	}
	
	public void onTouchEvent(MotionEvent e, GLVec2 pos)
	{
		if(focusedObject != null)
		{
			focusedObject.onTouchEvent(e, pos);
			return;
		}
		for(Object obj : screenItems)
		{
			if(obj instanceof TouchListener)
			{
				if(((TouchListener)obj).testPosition(pos))
				{
					((TouchListener)obj).onTouchEvent(e, pos);
				}
			}
		}
	}
	
	
	
	public abstract void onBack();
}
